package com.lzw.config;

import com.lzw.app.ClientApp;
import com.lzw.app.InstanceRepository;
import com.lzw.property.LzwProperties;
import com.lzw.property.ServerProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @author LZW
 */
@Configuration
@EnableConfigurationProperties({LzwProperties.class, ServerProperties.class})
public class ClientAutoConfiguration {
    //启动应用
    @Bean
    @ConditionalOnMissingBean(ClientApp.class)
    public ClientApp clientApp(LzwProperties lzwProperties, ServerProperties serverProperties, InstanceRepository instanceRepository) throws IOException {
        return ClientApp.getInstance(lzwProperties, serverProperties, instanceRepository);
    }

    //启动应用
    @Bean
    @ConditionalOnMissingBean(InstanceRepository.class)
    public InstanceRepository instanceRepository(LzwProperties lzwProperties, ServerProperties serverProperties) throws IOException {
        return new InstanceRepository();
    }
}
